package com.carsystems.controller;

import com.carsystems.mapper.AppealMapper;
import com.carsystems.pojo.Appeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AppealController {
    @Autowired
    private AppealMapper appealMapper;

//查询全部申诉状态信息
    @GetMapping("/appealList")
    public List<Appeal> appealList(){
        List<Appeal> appeals = appealMapper.appealList();
        return appeals;
    }

    //按appeal_id查询申诉状态
    @GetMapping("/appealid")
    public Appeal appealid(Integer appeal_id){
       return appealMapper.selectByPrimaryKey(appeal_id);
    }

    //增加一条申诉状态
    @ResponseBody
    @PostMapping("/addAppeal")
    public String addAppeal(@RequestBody Appeal appeal){
       appealMapper.addAppeal(appeal);
       if (appeal != null){
           return "success";
       }else {
           return "fail";
       }
    }

    //修改一条申诉状态信息
    @ResponseBody
    @PostMapping("/updateAppeal")
    public  String updateAppeal(@RequestBody Appeal appeal){
        int row = appealMapper.updateAppeal(appeal);
        appealMapper.selectByPrimaryKey(appeal.getAppeal_id());
        if (row ==1){
            return "success";
        }else {
            return "fail";
        }
    }

    //删除一条申诉状态信息
    @ResponseBody
    @GetMapping("/deleAaapeal")
    public String deleAaapeal( Appeal appeal){
        int row = appealMapper.deleAppeal(appeal.getAppeal_id());
        if (row ==1){
            return "success";
        }else {
            return "fail";
        }
    }
}
